home *** CD-ROM | disk | FTP | other *** search
/ The Best of MacTutor - S…e Code for Volumes 1 to 5 / The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin / Source Code / #43 (Apr 89) / Designer CDEF Code / DesignerButtons.Pas < prev    next >
Pascal/Delphi Source File  |  1989-01-06  |  6KB  |  115 lines

  1. PROGRAM DesignerButtons;
  2. {Program name:DesignerButtons.Pas   }
  3. {Function:  This is the main module for this program.  }
  4. {History: 12/19/88 Original by Prototyper.   }
  5. {  Modified 1/6/89                     }
  6.     USES
  7.         AboutDialog, ExampleWindow, InitTheMenus, HandleTheMenus;
  8.     VAR                                   {Main variables}
  9.         myEvent : EventRecord;                {Event record for all events}
  10.         doneFlag : boolean;                   {Exit program flag}
  11.         code : integer;                       {Determine event type}
  12.         whichWindow, theMainWindow : WindowPtr;              {See which window for event}
  13.         mResult : longint;                    {Menu list and item selected values}
  14.         theMenu, theItem : integer;            {Menu list and item selected}
  15.         chCode : integer;                   {Key code}
  16.         ch : char;                          {Key pressed in Ascii}
  17.  
  18. BEGIN                                 {Start of main body}
  19.  
  20.     MoreMasters;                        {This reserves space for more handles}
  21.     InitGraf(@thePort);                 {Quickdraw Init}
  22.     InitFonts;                          {Font manager init}
  23.     InitWindows;                        {Window manager init}
  24.     InitMenus;                          {Menu manager init}
  25.     TEInit;                             {Text edit init}
  26.     InitDialogs(NIL);                   {Dialog manager}
  27.  
  28.     FlushEvents(everyEvent, 0);         {Clear out all events}
  29.     InitCursor;                         {Make an arrow cursor}
  30.  
  31.     doneFlag := FALSE;                    {Do not exit program yet}
  32.  
  33.     Init_My_Menus;                      {Initialize menu bar}
  34.  
  35.     Init_ExampleWindow;                 {Initialize the window routines}
  36.     Open_ExampleWindow(theMainWindow);                 {Open the window routines at program start}
  37.  
  38.     REPEAT                              {Start of main event loop}
  39.         SystemTask;                       {For support of desk accessories}
  40.  
  41.         IF GetNextEvent(everyEvent, myEvent) THEN {If event then...}
  42.             BEGIN                           {Start handling the event}
  43.                 code := FindWindow(myEvent.where, whichWindow); {Get which window the event happened in}
  44.  
  45.                 CASE myEvent.what OF            {Decide type of event}
  46.  
  47.                     MouseDown :                   {Mouse button pressed}
  48.                         BEGIN                       {Handle the pressed button}
  49.                             IF (code = inMenuBar) THEN {See if a menu selection}
  50.                                 BEGIN                   {Get the menu selection and handle it}
  51.                                     mResult := MenuSelect(myEvent.Where); {Do menu selection}
  52.                                     theMenu := HiWord(mResult); {Get the menu list number}
  53.                                     theItem := LoWord(mResult); {Get the menu list item number}
  54.                                     Handle_My_Menu(doneFlag, theMenu, theItem); {Handle the menu}
  55.                                 END;                    {End of inMenuBar}
  56.  
  57.                             IF (code = inContent) THEN {See if in a window}
  58.                                 BEGIN                   {Handle the hit inside a window}
  59.                                     IF (whichWindow <> FrontWindow) THEN {See if already selected or not, in front if selected}
  60.                                         SelectWindow(whichWindow) {Select this window to make it active}
  61.                                     ELSE                    {If already in front the already selected}
  62.                                         BEGIN                 {Handle the button in the content}
  63.                                             SetPort(whichWindow); {Get ready to draw in this window}
  64.                                             Do_ExampleWindow(myEvent); {Handle this window}
  65.                                         END;                  {End of else}
  66.                                 END;                    {End of inContent}
  67.  
  68.                             IF (code = inSysWindow) THEN {See if a DA selection}
  69.                                 SystemClick(myEvent, whichWindow); {Let other programs in}
  70.  
  71.                         END;                        {End of MouseDown}
  72.  
  73.                     KeyDown, AutoKey :              {Handle key inputs}
  74.                         BEGIN                       {Get the key and handle it}
  75.                             WITH myevent DO           {Check for menu command keys}
  76.                                 BEGIN                   {}
  77.                                     chCode := BitAnd(message, CharCodeMask); {Get character}
  78.                                     ch := CHR(chCode);    {Change to ASCII}
  79.                                     IF (Odd(modifiers DIV CmdKey)) THEN {See if Command key is down}
  80.                                         BEGIN               {}
  81.                                             mResult := MenuKey(ch); {See if menu selection}
  82.                                             theMenu := HiWord(mResult); {Get the menu list number}
  83.                                             theItem := LoWord(mResult); {Get the menu item number}
  84.                                             IF (theMenu <> 0) THEN {See if a list was selected}
  85.                                                 Handle_My_Menu(doneFlag, theMenu, theItem); {Do the menu selection}
  86.                                         END;                 {}
  87.                                 END;                    {End for with}
  88.                         END;                        {End for KeyDown,AutoKey}
  89.  
  90.                     UpDateEvt :                   {Update event for a window}
  91.                         BEGIN                       {Handle the update}
  92.                             whichWindow := WindowPtr(myEvent.message); {Get the window the update is for}
  93.                             BeginUpdate(whichWindow); {Set the clipping to the update area}
  94.                             Update_ExampleWindow(whichWindow); {Update this window}
  95.                             EndUpdate(whichWindow);   {Return to normal clipping area}
  96.                         END;                        {End of UpDateEvt}
  97.  
  98.                     ActivateEvt :                 {Window activated event}
  99.                         BEGIN                       {Handle the activation}
  100.                             whichWindow := WindowPtr(myevent.message); {Get the window to be activated}
  101.                             IF odd(myEvent.modifiers) THEN {Make sure it is Activate and not DeActivate}
  102.                                 SelectWindow(whichWindow); {Activate the window by selecting it}
  103.                         END;                        {End of ActivateEvt}
  104.  
  105.                     OTHERWISE                     {Used for debugging, to see what other events are coming in}
  106.                         ;                        {End of otherwise}
  107.  
  108.                 END;                            {End of case}
  109.  
  110.             END;                            {end of GetNextEvent}
  111.     UNTIL doneFlag;                     {End of the event loop}
  112.  
  113.     DisposeWindow(theMainWindow);    {Will bomb if you don't dispose of it}
  114.  
  115. END.                                    {End of the program}